org 0x7c00
[bits 16]
; init seg reg,stack pointer
xor ax,ax
mov ds,ax
mov ss,ax
mov es,ax
mov fs,ax
mov gs,ax

mov sp,0x7c00
mov ax,0xb800
mov gs,ax

; print string
mov ax,0x1301
mov bx,0x0163
mov cx,strlen
mov dx,0x0c0e
mov bp,string
int 10h

;(2,0)start direction
mov cx,0x0101
mov dx,0x0200

printchar:
; random char
call random
call print
call delay
call judge
jmp $

random:
push cx
push dx

mov ah,2ch
int 21h
mov bx,dx
shr bh,3
xor bh,bl
sub bh,bl
xor bh,bl
add bl,bh
;and bl,0x7f	;limit ancii
call limitnum

pop dx 
pop cx
ret	; bx store info

limitnum:
mov edx,0
mov eax,0
mov al,bl
mov cx,0
mov cl,10
idiv cx
mov bl,48	; '0' ancii
add bl,dl
ret

print:		;write mem
push cx
push dx

mov ax,bx
mov bx,0
mov bl,dh
imul bx,bx,80
mov dh,0
add bx,dx
shl bx,1
mov [gs:bx],ax

pop dx
pop cx
ret

delay:
push ecx

mov ecx,10000000
delay_loop:
dec ecx
jnz delay_loop

pop ecx
ret

judge:
add dh,ch
add dl,cl
cmp dh,24
je bounce_x
cmp dh,0
je bounce_x
cmp dl,79
je bounce_y
cmp dl,0
je bounce_y
jmp printchar

bounce_x:
neg ch
jmp printchar

bounce_y:
neg cl
jmp printchar

string db "22336271 ysj,I'm your operating system!Thank you:)"
strlen equ $ - string

times 510 - ($-$$) db 0
dw 0xaa55
